package com.cskaoyan.wordmemorize.controller.app;


import com.cskaoyan.wordmemorize.auth.StpKit;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.VocDTO;
import com.cskaoyan.wordmemorize.dto.app.DisplayBookVocDTO;
import com.cskaoyan.wordmemorize.dto.app.DisplayChapterDTO;
import com.cskaoyan.wordmemorize.dto.app.UserBookStatisticsDTO;
import com.cskaoyan.wordmemorize.request.AppVocPageRequest;
import com.cskaoyan.wordmemorize.service.VocService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user/voc")
public class AppUserVocController {

    @Resource
    VocService vocService;

    /**
     * 获取有章节单词数据
     * @return PageDTO<DisplayChapterDTO> 有章节单词数据分页查询结果
     */
    @GetMapping("book/chapter/display")
    public Result<PageDTO<DisplayChapterDTO>> getDisplayBookChapterVocsInfo(AppVocPageRequest pageRequest) {

        PageDTO<DisplayChapterDTO> displayBookChapterVocsInfo = vocService.getDisplayBookChapterVocsInfo(pageRequest);

        return Result.ok(displayBookChapterVocsInfo);
    }

    @GetMapping("detail/{vocId}")
    public Result<VocDTO> getVocDetail(@PathVariable("vocId") Long vocId) {

        Long loginId = StpKit.USER.getLoginIdAsLong();

        VocDTO vocDetail = vocService.getVocDetail(vocId,loginId);

        return Result.ok(vocDetail);
    }

    // 获取无章节单词信息
    @GetMapping("book/display")
    public Result<PageDTO<DisplayBookVocDTO>> etDisplayBookVocsInfo(AppVocPageRequest pageRequest){


        PageDTO<DisplayBookVocDTO> displayBookVocsInfo = vocService.getDisplayBookVocsInfo(pageRequest);

        return Result.ok(displayBookVocsInfo);
    }


    @GetMapping("{bookId}/selection/info")
    public Result<UserBookStatisticsDTO> getUserChooseCountInBook(@PathVariable Long bookId){

        UserBookStatisticsDTO userChooseCountInBook = vocService.getUserChooseCountInBook(StpKit.USER.getLoginIdAsLong(), bookId);

        return Result.ok(userChooseCountInBook);
    }

}
